package com.opNaga.bpmp.connectingObject;

import com.opNaga.bpmp.BPMPElement;

/**
 * User: Junyi BEI
 * Date: 19/01/2012
 * Time: 14:00
 */
public abstract class ConnectingObject extends BPMPElement {
  protected BPMPElement source;
  protected BPMPElement target;

  public ConnectingObject() {
    super();
  }

  public ConnectingObject(String t) {
    super(t);
  }

  @Override
  public boolean destroy() {
    return super.destroy();
  }

  public boolean setTarget(BPMPElement targetElement) {
    if(targetElement == null) {
      target = targetElement;
      return standardMessage(394);
    }
    if(target != null) {
      return standardMessage(300, targetElement, target);
    }
    if(!validateTarget(targetElement)) {
      return standardMessage(301, targetElement);
    }
    target = targetElement;
    return standardMessage(390, targetElement);
  }

  public BPMPElement getTarget() {
    return target;
  }

  public boolean setSource(BPMPElement sourceElement) {
    if(sourceElement == null) {
      source = sourceElement;
      return standardMessage(395);
    }
    if(source != null) {
      return standardMessage(310, sourceElement, source);
    }
    if(!validateSource(sourceElement)) {
      return standardMessage(311, sourceElement);
    }
    source = sourceElement;
    return standardMessage(391, sourceElement);
  }

  public BPMPElement getSource() {
    return source;
  }

  public abstract boolean validateSource(BPMPElement be);

  public abstract boolean validateTarget(BPMPElement be);


}
